import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/lifeCircle/data/repository/life_repository.dart';

class LifeTopicAddCommentUsecase {
  final LifeRepository _repository;

  const LifeTopicAddCommentUsecase(this._repository);

  Future<void> execute({
    required String topicId,
    required String content,
    String? parentId,
    String? imageSrc,
    String? toUserId,
  }) async {
    try {
      await _repository.addTopicComment(
        topicId: topicId,
        content: content,
        parentId: parentId,
        imageSrc: imageSrc,
        toUserId: toUserId,
      );
    } on BusinessException {
      rethrow;
    } catch (e, st) {
      Log.e('LifeTopicAddCommentUsecase 失败', e.toString(), st);
      throw Exception('发表评论失败');
    }
  }
}
